package com.stock_t.config.datasource;

import javax.sql.DataSource;

import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;

/**
 * 多数据源事务管理器
 */
@Configuration
@EnableTransactionManagement
public class DataSourceTransactionManagerConfig extends DataSourceTransactionManagerAutoConfiguration {

    /**
     * 使用动态数据源创建事务管理器
     */
    @Bean
    @DependsOn({"masterDataSource", "slaveDataSource"})
    public PlatformTransactionManager transactionManager(com.stock_t.config.datasource.DynamicDataSource dynamicDataSource) {
        return new DataSourceTransactionManager(dynamicDataSource);
    }
} 